package com.example.demo.aop;

import com.example.demo.entity.enums.CodeEnum;
import com.example.demo.util.RUtil;
import com.example.demo.vo.R;
import com.example.exceptions.RException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R handle(Exception e){
        if (e instanceof RException){
            RException re=(RException) e;
            return RUtil.error(re.getCode(),re.getMessage());
        }
        return RUtil.error(CodeEnum.UNKNOWN_ERROR);
    }

}
